<!-- 参数查询 -->
<!-- <template>
	<div class="">参数查询</div>
</template>

<script>
	export default {
		name: "parameterQuery",
		components: {},
		data() {
			return {}
		},
		computed: {},
		created() {},
		methods: {},
	}
</script>

<style lang="scss" scoped></style> -->

<template>
    <div>
        <navigation-bar>
            <div class="searchContent">
                <el-select
                    v-model="device_type"
                    clearable
                    placeholder="请选择区域建筑/部门"
                    size="mini"
                    style="width: 180px; margin-right: 10px"
                >
                    <el-option v-for="item in device_typeList" :key="item.value" :label="item.label" :value="item.value" width="180px">
                    </el-option>
                </el-select>
                <el-time-picker
                    is-range
                    v-model="time2"
                    range-separator="-"
                    start-placeholder="开始时间"
                    end-placeholder="结束时间"
                    placeholder="选择时间段"
                    format="HH:mm"
                    size="mini"
                    style="width: 180px; margin-right: 10px"
                >
                </el-time-picker>
                <el-select v-model="status" clearable placeholder="请选择参数" size="mini" style="width: 150px; margin-right: 10px">
                    <el-option v-for="item in statusList" :key="item.value" :label="item.label" :value="item.value" width="150px">
                    </el-option>
                </el-select>
                <el-select v-model="status" clearable placeholder="请选择配置是否成功" size="mini" style="width: 150px; margin-right: 10px">
                    <el-option v-for="item in statusList" :key="item.value" :label="item.label" :value="item.value" width="150px">
                    </el-option>
                </el-select>
                <custom-button type="search" style="margin-right: 10px" @searchClick="searchClick"></custom-button>
                <custom-button type="reset" style="margin-right: 10px" @resetClick="resetClick"></custom-button>
                <custom-button type="download" @downloadClick="resetClick" title="导出" style="margin-right: 10px"></custom-button>
                <custom-button
                    type="custom"
                    icon="el-icon-arrow-down"
                    title="批量重新下发"
                    style="margin-right: 10px"
                    @customClick="customClick"
                ></custom-button>
                <!--				<custom-button type="print" title="打印使用记录"></custom-button>-->
            </div>
        </navigation-bar>
        <table-index
            :dataSource="dataSource"
            :tableColumns="tableColumns"
            :btnList="btnList"
            :pageSize="pageSize"
            :pageCount="pageCount"
            :pageNo="pageNo"
            @pageChange="pageChange"
            @resetXf="resetXf"
            selection
            @handleSelectionChange="handleSelectionChange"
            btnListWidth="80"
        ></table-index>

        <div v-if="dialogShow">
            <custom-dialog :title="dialogTitle" size="large" @dialogClose="dialogClose">
                <form-index :formConfig="formConfig" @submit="submit" :type="type" @formInputChange="formInputChange" ref="form">
                    <!--  <div>这里还可以插入其它内容进行拓展</div> -->
                </form-index>
            </custom-dialog>
        </div>
    </div>
</template>

<script>
import {baseInfoForm} from '@/assets/form/managementCenter/baseInfoForm'
import customDialog from '@/components/customComponents/customDialog'
import customButton from '@/components/customComponents/customForm/customButton'
import formIndex from '@/components/customComponents/customForm/formIndex'
import tableIndex from '@/components/customComponents/customeTable/tableIndex'
import navigationBar from '@/components/customComponents/managementCenter/navigationBar'
import {AjaxCommon, printAddress} from '@/libs/apiCommon'
import {CardId} from '@/libs/cardId'
import {PopupCommon} from '@/libs/popupCommon'
import {SessionCommon} from '@/libs/sessionCommon'
import {Utility} from '@/libs/utility'
import {csQueryData} from '@/mockData/controlCenter'
export default {
    components: {
        navigationBar,
        customButton,
        tableIndex,
        customDialog,
        formIndex
    },
    data() {
        return {
            time2:null,
            selectDeviceList: [],
            deviceName: '',
            device_type: '',
            device_typeList: Utility.getDictList('device_type'),
            status: '',
            statusList: Utility.getDictList('status'),
            // table 相关参数  begin
            dataSource: csQueryData,
            tableColumns: [
                {
                    prop: 'deviceName',
                    label: '用户'
                },
                {
                    prop: 'instrumentDeviceNo',
                    label: '配置时间',
                    width: 120
                },
                {
                    prop: 'price',
                    label: '总功率(kW)',
                    width: 120
                },
                {
                    prop: 'model',
                    label: '恶性负载限定值',
                    width: 120
                },
                {
                    prop: 'manufacturer',
                    label: '本地预付费负载控制',
                    width: 180
                },
                {
                    prop: 'productionDate',
                    label: '分时段控制',
                    width: 120
                },
                {
                    prop: 'deviceStatus',
                    label: '分时限流',
                    width: 120,
                    dictName: 'status'
                },
                {
                    prop: 'factoryNo',
                    label: '补助下发',
                    width: 120
                },
                {
                    prop: 'purchaseDate',
                    label: '补助核销',
                    width: 100
                },
                {
                    prop: 'startDate',
                    label: '透支',
                    width: 100
                },
                {
                    prop: 'technicalPram',
                    label: '账户清零',
                    width: 100
                },
                {
                    prop: 'deviceType',
                    label: '换房操作',
                    width: 100
                },
                {
                    prop: 'chargeByName',
                    label: '备注',
                    width: 120
                },
                {
                    prop: 'jdrq',
                    label: '检定日期',
                    width: 160,
                    dictName: 'device_type'
                }
            ],
            btnList: ['resetXf'],
            pageSize: 20,
            pageCount: 100,
            pageNo: 1,
            // table 相关参数  end
            // 弹窗是否显示
            dialogShow: false,
            // 弹窗标题 (新增修改不同)
            dialogTitle: '',
            // form的配置信息
            formConfig: baseInfoForm,
            type: 'add'
        }
    },

    methods: {
        handleSelectionChange(d) {
            this.selectDeviceList = d
        },
        printClick() {
            console.log(1111)
            let urlAdd = `${printAddress}/ccdc/tmrreport/pdf/show?1=1&_u=file:shebeibqV1.tmrreport.xml&_i=1&_r=1
`
            if (this.selectDeviceList.length > 0) {
                let ids = this.selectDeviceList
                    .map((t) => {
                        return t.id
                    })
                    .join(',')
                if (this.selectDeviceList.length < 2) {
                    urlAdd += '&id=' + ids
                } else {
                    urlAdd += '&ids=' + ids
                }
            }
            console.log(urlAdd)
            window.open(urlAdd)
        },
        formInputChange(e) {
            if (e.filedName == 'idCard') {
                const data = CardId.getInfoByCardId(e.value)
                if (data) {
                    let newData = e.allData
                    newData['birthday'] = data.birthday
                    newData['sex'] = data.sex
                    this.$refs.form.changeFormValue(newData)
                }
            }
        },
        submit(d) {
            let self = this
            console.log(d)
            if (d.id) {
                AjaxCommon('/ccdc/cfg/device/device/edit', 'post', d)
                    .then((res) => {
                        if (res.data.code == 200) {
                            PopupCommon.notify('success', '操作成功')
                            self.initPage()
                            self.dialogClose()
                            this.dialogClose()
                        } else {
                            PopupCommon.notify('error', res.data.message)
                        }
                    })
                    .catch((err) => {
                        PopupCommon.notify('error', err.message)
                    })
            } else {
                delete d.id
                AjaxCommon('/ccdc/cfg/device/device/add', 'post', d)
                    .then((res) => {
                        if (res.data.code == 200) {
                            PopupCommon.notify('success', '操作成功')
                            self.initPage()
                            self.dialogClose()
                        } else {
                            PopupCommon.notify('error', res.data.message)
                        }
                    })
                    .catch((err) => {
                        PopupCommon.notify('error', err.message)
                    })
            }
        },
        dialogClose() {
            this.dialogShow = false
        },
        searchClick() {
            this.pageNo = 1
            this.initPage()
        },
        resetClick() {
            this.deviceName = ''
            this.status = ''
            this.device_type = ''
        },
        addClick() {
            let formConfigItem = this.formConfig
            formConfigItem.map((t) => {
                Object.keys(t).map((res) => {
                    if (res == 'fieldName') {
                        t.filedValue = ''
                    }
                })
            })
            this.formConfig = formConfigItem
            this.type = 'add'
            this.dialogShow = true
            this.dialogTitle = '新增' + JSON.parse(SessionCommon.getCurrentMenuInfo()).title
        },
        // 分页点击事件
        pageChange(p) {
            this.pageNo = p
            this.initPage()
        },
        resetXf(d) {
            this.type = 'edit'
            let formConfigItem = this.formConfig
            formConfigItem.map((t) => {
                Object.keys(t).map((res) => {
                    if (res == 'fieldName') {
                        t.filedValue = d.data[t[res]]
                    }
                })
            })
            this.formConfig = formConfigItem
            this.dialogShow = true
            this.dialogTitle = '编辑' + JSON.parse(SessionCommon.getCurrentMenuInfo()).title
        },
        // 初始化事件
        initPage() {
            // let self = this
            // AjaxCommon("/ccdc/cfg/device/device/listByPage", "post", {
            // 	deviceName: this.deviceName,
            // 	deviceStatus: this.status,
            // 	deviceType: this.device_type,
            // 	pageNo: this.pageNo,
            // 	pageSize: this.pageSize,
            // }).then((res) => {
            // 	if (res.data.code == 200) {
            // 		self.dataSource = res.data.result.records
            // 		self.pageCount = res.data.result.total
            // 	} else {
            // 		PopupCommon.notify("error", res.data.message)
            // 	}
            // })
        }
    },
    mounted() {
        this.initPage()
    }
}
</script>

<style></style>
